package com.shuqi.model.parse.parser;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.model.bean.OfferWallInfo;
import com.shuqi.model.parse.HandlerBase;

/**
 * 推广详情数据解析
 * 
 * @author linyuren
 * 
 */
public class OfferWallItemParser extends HandlerBase {

    private OfferWallInfo info;
    private List<String> imgUrls;

    @Override
    public List<OfferWallInfo> getParsedData() {
        List<OfferWallInfo> list = new ArrayList<OfferWallInfo>();
        list.add(this.info);
        return list;
    }

    @Override
    public void startDocument() throws SAXException {
        this.info = new OfferWallInfo();
        this.imgUrls = new ArrayList<String>();
        info.setImgUrls(imgUrls);
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs)
            throws SAXException {
        if (localName.equals("item")) {
            info.setName(isNull(attrs, "name"));
            info.setVersionName(isNull(attrs, "versionname"));
            info.setGroom(isNull(attrs, "groom"));
            info.setIconUrl(isNull(attrs, "img"));
            info.setIntro(isNull(attrs, "intro"));
            info.setSize(isNull(attrs, "size"));
            info.setUpdateTime(isNull(attrs, "updatetime"));
            info.setSystem(isNull(attrs, "system"));
            info.setBrief(isNull(attrs, "brief"));
            info.setVersionCode(isNull(attrs, "versioncode"));
            info.setDownloadUrl(isNull(attrs, "url"));
        } else if (localName.equals("image")) {
            imgUrls.add(isNull(attrs, "url"));
        }
    }

    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
    }

}
